<!DOCTYPE html>

<html lang="zh-CN">
	<head>
		<meta charset="utf-8" />
		<meta name="renderer" content="webkit" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<title>会员列表</title>
		<script src="/static/js/jquery-1.9.1.min.js"></script>
        <script src="/static/bootstrap.modal/bootstrap.js"></script>
        <script src="/static/js/base.js"></script>
        <script src="/static/js/avalon.js"></script>
        <script src="/static/js/eqx.js"></script>
        <script src="/static/js/goods/jquery.colorbox-min.js"></script>
        <script src="/static/js/goods/zzsc.js"></script>
		
		
        <link media="all" href="/static/bootstrap.modal/bootstrap.min.css" rel="stylesheet">
        <link media="all" href="/static/css/main.css" rel="stylesheet">
        <link media="all" href="/static/css/base.hy.css" rel="stylesheet">
        <link media="all" href="/static/css/goods.css" rel="stylesheet">
		
		<style type="text/css">
			  .list-content img{margin-right: 8px}
	.check{cursor:pointer}
	table{width: :100%;}
		</style>

		
	</head>
<body>

<div class="box" ms-controller="table">
    <div class="admin-top">
        <div class="admin-title">会员列表 <a href="/article_list.html" class="search-keyword ml5">文章列表</a></div>
		<div class="search-content">

    <div class="list-content">
    	<table class='table table-condensed'>
			<tr class='list_nav'>
          <td>id</td>
			    <td>会员昵称</td>
			    <td>账号密码</td>
			    <td>创建时间</td>
			    <td>操作</td>
			</tr>
      {{range $key, $val := .user}}
			<tr>
          <td>{{$val.Id}}</td>
          <td>{{$val.Username}}</td>
          <td>{{$val.Password}}</td>
          <td>{{$val.Created}}</td>
          <td>
            <a href="javascript:;" class="search-keyword" ms-click="delMemberId({{$val.Id}})">详情</a>
            <a href="javascript:;" class="search-keyword" ms-click="delMember({{$val.Id}})">删除</a>
          </td>
      </tr>
       {{end}}
		  </table>

      <div>
        <form>
          <input type="text" ms-duplex="content.username">
          <input type="text" ms-duplex="content.password">
          <a href="javascript:;" class="search-keyword" ms-click="addMember()">新增</a>
          <a href="javascript:;" class="search-keyword" ms-click="setMember()">修改</a>
        </form>
      </div>

      <div>
        <form action="/user/uploads"  enctype="multipart/form-data"  method="post">
            <input type="file" name="file" ms-duplex="content.file"><br><br>    
            <input type="submit" value="上传相关文件">
            <a href="javascript:;" class="search-keyword" ms-click="userupload()">上传</a>
        </form>
      </div>
    </div>
</div>
<script type="text/javascript"> 
	var vm = avalon.define({
		$id : "table",
		list : [],
    content:{username:'',password:'',id:0,file:""},
		//根据ID删除单个会员
		delMemberId: function(id){
			$.post('/user/byId',{id:id}, function(json) {
  			vm.content.username = json.Username;
        vm.content.password = json.Password;
        vm.content.id = json.Id;
		  },'json');
		},

	  //新增会员
		userupload: function(){
			$.post('/user/uploads',{file:vm.content.file}, function(json) {
  			
		  },'json');
		},
    //新增会员
		addMember: function(){
			$.post('/user/add',{username:vm.content.username,password:vm.content.password}, function(json) {
  			location.reload() 
		  },'json');
		},
    //删除会员
		delMember: function(id){
			$.post('/user/del',{id:id}, function(json) {
        if(json==1){
          alert("删除成功")
          location.reload() 
        }else{
          alert("删除失败")
        }
		  },'json');
		},
    //修改会员资料
    setMember: function(){
			$.post('/user/set',{id:vm.content.id,username:vm.content.username,password:vm.content.password}, function(json) {
  			if(json==1){
          alert("修改成功")
          location.reload() 
        }else{
          alert("修改失败")
        }
		  },'json');
		},
    getList: function(){
			$.post('/user/list',{}, function(json) {
  			
		  },'json');
		}
	});

  vm.getList();
</script>
</body>
</html>
